﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security;
using BLL;
using System.IO;
using AjaxControlToolkit;
using System.Web.Script.Serialization;
using BLL.Pictures;

public partial class AjaxFileUploadTest : System.Web.UI.UserControl
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
       
    }

    protected void FileUploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
    {

        Stream stream = HttpContext.Current.Request.InputStream;
        string fileName = e.FileName;
        string contentType = e.ContentType;
        byte[] pictureBinary = new byte[stream.Length];
        
        string fileExtension = Path.GetExtension(fileName);
        if (!String.IsNullOrEmpty(fileExtension))
            fileExtension = fileExtension.ToLowerInvariant();

        if (String.IsNullOrEmpty(contentType))
        {
            switch (fileExtension)
            {
                case ".bmp":
                    contentType = "image/bmp";
                    break;
                case ".gif":
                    contentType = "image/gif";
                    break;
                case ".jpeg":
                case ".jpg":
                case ".jpe":
                case ".jfif":
                case ".pjpeg":
                case ".pjp":
                    contentType = "image/jpeg";
                    break;
                case ".png":
                    contentType = "image/png";
                    break;
                case ".tiff":
                case ".tif":
                    contentType = "image/tiff";
                    break;
                default:
                    break;
            }
        }

        int ret = Picture.InsertPicture(pictureBinary, contentType, null, true);
    }
}
